package com.sihan.framework.etm.service.business.impl;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.framework.excel.ExcelWriter;
import com.framework.excel.enums.Excels;
import com.sihan.framework.etm.common.util.RequestUtil;
import com.sihan.framework.etm.mapper.business.ExcelMapper;
import com.sihan.framework.etm.service.business.ExcelService;
import com.sihan.framework.etm.vo.excel.PlanDetailVO;
import com.sihan.framework.etm.vo.excel.ToolStandingBookVO;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
public class ExcelServiceImpl implements ExcelService {
	
	@Autowired
	private ExcelMapper excelMapper;

	@Override
	public void downloadPlanDetail(HttpServletRequest request, HttpServletResponse response, 
			String planId) {
		List<PlanDetailVO> details = excelMapper.excelPurchasePlanDetail(planId);
		try {
			ExcelWriter.of(Excels.XLS).sheet("计划详情导出", details).
			write(RequestUtil.getResponse( response, request,"计划详情导出").getOutputStream());
		} catch (IOException e) {
			log.error("异常",e);
		} catch (Exception e) {
			log.error("异常",e);
		}
	}

	@Override
	public void downloadToolStandingbook(HttpServletRequest request, HttpServletResponse response, String typeId) {
		List<ToolStandingBookVO> details = excelMapper.excelToolStandingBook(typeId);
		try {
			ExcelWriter.of(Excels.XLS).sheet("工器具台账导出", details).
			write(RequestUtil.getResponse( response, request,"工器具台账导出").getOutputStream());
		} catch (IOException e) {
			log.error("异常",e);
		} catch (Exception e) {
			log.error("异常",e);
		}
	}

}
